package com.object.module.cbb.frontEnd;

import com.object.configuration.utils.PageUtils;
import com.object.configuration.utils.Q;
import com.object.module.cbb.entity.CbbUserEntity;
import com.object.module.cbb.service.CbbUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 *  商户
 *
 * @author 小🌤
 * @email 1578442339@qq.com
 * @date 2021-12-29 21:06:27
 */
@RestController
@RequestMapping("/frontend/user")
public class FrontEndCbbUserController {
    @Autowired
    private CbbUserService cbbUserService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public Q list(@RequestParam Map<String, Object> params) {
        PageUtils page = cbbUserService.queryPage(params);
        return Q.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{urId}")
    public Q info(@PathVariable("urId") Integer urId) {
            CbbUserEntity cbbUser = cbbUserService.getById(urId);
            return Q.ok().put("cbbUser", cbbUser);
    }


    /**
     * 刷新头像地址
     */
    @GetMapping("/update/headPortrait/{urId}")
    public Q headPortrait(@PathVariable("urId") Integer urId) {
        String avatarUrl=cbbUserService.headPortrait(urId);
        return Q.ok().put("url",avatarUrl);
    }



    /**
     * 保存
     */
    @RequestMapping("/save")
    public Q save(@RequestBody CbbUserEntity cbbUser) {
            cbbUserService.save(cbbUser);
            return Q.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public Q update(@RequestBody CbbUserEntity cbbUser) {
        boolean flag= cbbUserService.updateUser(cbbUser);
        return flag?Q.ok():Q.error();
    }


}
